package com.aspirecn.core.datacache;

import java.io.File;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 本地缓存基础类
 * 加载IP地址段、UA数据，XSS校验字符串，网关数据时用
 * 也就是说，从本地文件加载数据到内存都可以用
 * @author wangxinning
 *
 */
public abstract class BaseLocalCache {

	//首次加载
	public abstract void load();
	
	//清空缓存
	public abstract void clear();
	
	//再次加载，考虑内存清除，溢出的问题
	public abstract void reload();

	//加载文件
	protected File dataFile;
	
	//前次加载数据文件下载时间
	protected long fileDownloadTime = 0;

	public long getFileDownloadTime() {
		return fileDownloadTime;
	}

	public void setFileDownloadTime(long fileDownloadTime) {
		this.fileDownloadTime = fileDownloadTime;
	}

	//跟上次加载时间是否变化
	protected boolean fileIsChange()
	{
		long fileDownloadTime = dataFile.lastModified();;
		if( this.fileDownloadTime != fileDownloadTime )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//更新时间标记
	protected void updateFileDownloadTime()
	{
		this.fileDownloadTime = dataFile.lastModified();
	}
	
	//加载标记
	protected AtomicBoolean loading = new AtomicBoolean(false);
	
	public boolean isLoading()
	{
		return loading.get();
	}
}